var ecommRecordCtrl  = new XFApp.client();
$.views.converters({
	
	fauditStatus : function(value) {
		
		if(!value){
			return "";
		}
		for(index in auditStates){
			var auditState = auditStates[index];
			if(auditState.dictCode == value){
				return auditState.dictName;
			}
		}
		return  "未知类型("+value+")";
	},
	
});

XFApp.client.prototype.ecommRecord = {
		successCode : 10000,	
		ecommRecordPage : null,
		urlItems : {
			initListURL: basePath+"/userCenter/ecommerceRecord/init",
			deleteURL: basePath+"/userCenter/ecommerceRecord/delete",
		},
		
		event : function (){			
			_this = this;			
			//$("#auditState").text(_this.fauditStatus(val));			
			$("#searchButton").on("click",function(){
				_this.load();
			});
		},	
		
		del : function(id){
			
			var type = $("#delRecord").attr("title");
			
			webAlert({
	            title:'提示',
	            content:'确认执行'+type+'操作吗?',
	            opacity:.5,
	            bg:"gray",
	            width:300,
	            height:10,
	            button:[
	                    {
	                    name:"确定",
	                    callback:function(){
	                    	_this.delConfirm(id);
	                    	this.close();
	                    }
	                    },{
	                    name:"取消",
	                    callback:function(){
	                  	  this.close();
	                    }
	                    }]
	         });
			
		},		
		
		

		delConfirm: function(id){
	
			var params = {	
					id : id,
					isRemoved:1 //1-逻辑删除
			}
	
			$.ajax({
				url :_this.urlItems.deleteURL,
				data : params,
				dataType : "json",
				type : 'post',
				success : function(data) {				
					if(data.code==_this.successCode){ 
						window.webDialogUtil.alert("提示",data.msg);	    				
						//刷新
						_this.load();	    				
		    	        		
					}else{
						window.webDialogUtil.alert("提示",data.msg);
					}
				}
			});			
	
		},
		
		
		load : function (){		
			
			ecommRecordVo = {
					customerCode : $("#customerCode").val(),
					customerName : $("#customerName").val()
    		};
			if(!!_this.ecommRecordPage){
				_this.ecommRecordPage.page("remote",0,ecommRecordVo);
			}else{
				_this.ecommRecordPage = $("#page").page({
				pageSize : 10,
				remote: {
					url: _this.urlItems.initListURL,
			        params: ecommRecordVo, 
			        success: function (data, pageIndex) {
			        	if(data.code==_this.successCode){
			        		if(null == data.result 
										|| null == data.result.itemList
											|| data.result.itemList.length < 1){
			        			$("#page_grid").html('<tr><td align="center" colspan="15">暂无数据</td></tr>');
			        		}else{
			        			$("#page_grid").html($("#pageTmp").render(data.result.itemList));
			        		}
			        		
			        	}else{
			        		  window.webDialogUtil.alert("提示",data.msg);
			        	}
			        },
			        error : function(){
			        	window.webDialogUtil.alert("提示",data.msg);
			        }
				},
				firstBtnText : '首页',
				lastBtnText : '尾页',
				prevBtnText : '上一页',
				nextBtnText : '下一页',
				showInfo : true,
				showJump : true,
				jumpBtnText : '跳转',
				showPageSizes : true,
				infoFormat : '共{pageCount}页'
			});	
		   }			
		},
		
		
		
},

$(function(){	
	
	ecommRecordCtrl.ecommRecord.event();	
	ecommRecordCtrl.ecommRecord.load();
	
});